%"best_index" - in 1s/0s shows the postion of a trial, "best_trigger" - again shows the postion but in the range 1 .. n
function [best_index,best_trigger] = generate_trials_postitions_using_single_discrete_channel(m, trigger_channel, trial_value, class_value)
% gtec tagging with Pulsar

classes = (trigger_channel == class_value);
trials = (trigger_channel == trial_value);

class_end_positions = find(diff(classes)==1);

trial_positions = find(diff(trials)==1);

trial_positions = trial_positions + 1;

if (m==1)
   result = trial_positions(trial_positions'<class_end_positions(m));
else 
    result = trial_positions(trial_positions'>class_end_positions(m-1) & trial_positions'<class_end_positions(m)); 
end;
    

best_index = result;
best_trigger = trials;





